home *** CD-ROM | disk | FTP | other *** search
- Path: engnews1.Eng.Sun.COM!taumet!clamage
- From: "I\qaky P\irez Gonz\alez" <inaky@eneline.es>
- Newsgroups: comp.std.c++
- Subject: Is typeof legal under ANSI C++?
- Date: 10 Apr 1996 14:56:38 GMT
- Organization: ?
- Approved: clamage@eng.sun.com (comp.std.c++)
- Message-ID: <4kgi76$qf1@engnews1.Eng.Sun.COM>
- NNTP-Posting-Host: taumet.eng.sun.com
- Mime-Version: 1.0
- Content-Type: TEXT/PLAIN; charset="us-ascii"
- X-Nntp-Posting-Host: 194.224.7.5
- X-Lines: 79
- Content-Length: 2008
- Originator: clamage@taumet
-
-
- Hi!!
-
- I'm facing a BIG problem, developing under GCC/2.7.2 and the only
- sollution I've found is using the "typeof()" keyword, but I'm afraid of
- losing compatibility and those things ...
-
- So, my cuestion is that of the subject. Does typeof() conform to
- ANSI C++?
-
- The problem is the following: I have a templated class, named A,
- which may be applied the array operator. Then I have another templated
- class, name it B which is an smart pointer to classes of any type (in
- fact, this is used for classes which have a resource count which
- has to be kept updated ... more or less like the Fresco toolkit and a
- lot more I don't know of :).
-
- Well, the idea is that when "working daily" with objects of class
- A, they'll be pointers, and when storing the pointers into smart pointers,
- you have to dereference it and then apply the operator array, like
- (*b)[4], which is kind of ugly. This is not too important, but when you
- are refering to nested arrays of smart pointers, it keeps going uglier
- (for example (*(*(*b)[3])[1])[4] for a three-level nested array).
-
- So, if I manage to make a method in the smart pointer which passes
- the array operator to the item it points to and returns a reference to the
- object it returns, I am done. Here is where the typeof() keyword appears.
- If not, I don't know which type to return in the array operator of the
- smart pointer.
-
- Here is the simplified code explaining the example ...
-
- template<class T>
- class A
- {
- public:
- virtual T& operator [] (unsigned int i) {return 3; };
- };
-
- template<class T>
- class B
- {
- public:
- virtual typeof((*a)[0]) operator[] (unsigned int a)
- {
- return (*a)[i];
- };
- virtual operator T* () const
- {
- return a;
- }
- T* a;
- };
-
- int main (void)
- {
- A<int> df;
- B<A<int> > tf;
-
- return tf[2];
- }
-
- Well, this is all folks :) TIA
-
- --Inaky Perez Gonzalez <inaky@peloncho.fis.ucm.es> <2:341/5.31@fidonet.org> --
- --- PGP Key fingerprint = 8E 34 3A 62 64 99 E2 44 AD 7B 30 D9 DD FF 3E 4C ---
- (PGP public key available via finger/e-mail request)
-
-
-
-
- [ comp.std.c++ is moderated. To submit articles: try just posting with ]
- [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
- [ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
- [ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
- [ Comments? mailto:std-c++-request@ncar.ucar.edu ]
-